var fs = require("fs");
var id3 = require("id3");
var path = require("path");

module.exports = function(){
	
	var foundFiles = [];
	
	var getTags = function(f) {
		if (path.extname(f) == ".mp3"){
			fs.readFile(f, function (err, data){
				if (err) throw err;
				return id3(data);
			});
		}
	};
	
	var getFiles = function(p, depth){
		console.log(p);
		p = path.join(path.resolve(__dirname,'..'),p);
		fs.readdir(p, function(err, files){
			if(err) throw err;
			for(var i in files){
				console.log(files[i]);
				foundFiles.push(getTags(path.join(p,files[i])));
			}
		});
		return foundFiles;
	};
	
	return {
		getFiles: getFiles
	};
};